void LibRaw::pentax_4shot_load_raw()
{
+ size_t alloc_sz = size_t(imgdata.sizes.raw_width) * (size_t(imgdata.sizes.raw_height) + 16) * 4 * sizeof(ushort);
+ if (INT64(alloc_sz) > INT64(imgdata.rawparams.max_raw_memory_mb) * INT64(1024 * 1024))
+ throw LIBRAW_EXCEPTION_TOOBIG;
+
#ifdef LIBRAW_CALLOC_RAWSTORE
ushort *plane = (ushort *)calloc(size_t(imgdata.sizes.raw_width) *
size_t(imgdata.sizes.raw_height), sizeof(ushort));
ushort *plane = (ushort *)malloc(size_t(imgdata.sizes.raw_width) *
size_t(imgdata.sizes.raw_height) * sizeof(ushort));
#endif
- int alloc_sz = imgdata.sizes.raw_width * (imgdata.sizes.raw_height + 16) * 4 *
- sizeof(ushort);
+ if (!plane)
+ throw LIBRAW_EXCEPTION_ALLOC;
+
#ifdef LIBRAW_CALLOC_RAWSTORE
ushort(*result)[4] = (ushort(*)[4])calloc(alloc_sz,1);
#else
ushort(*result)[4] = (ushort(*)[4])malloc(alloc_sz);
#endif
+ if(!result)
+ throw LIBRAW_EXCEPTION_ALLOC;
+
struct movement_t
{
int row, col;
libraw_internal_data.internal_data.input);
if (ifd->sample_format == 3)
- float_raw_image = (float *)calloc(tiles.tileCnt * tiles.tileWidth * tiles.tileHeight *ifd->samples, sizeof(float));
+ {
+ INT64 raw_bytes = tiles.tileCnt * tiles.tileWidth * tiles.tileHeight * ifd->samples * sizeof(float);
+ if (raw_bytes > INT64(imgdata.rawparams.max_raw_memory_mb) * INT64(1024 * 1024))
+ throw LIBRAW_EXCEPTION_TOOBIG;
+ float_raw_image = (float *)calloc(tiles.tileCnt * tiles.tileWidth * tiles.tileHeight * ifd->samples, sizeof(float));
+ if (!float_raw_image)
+ throw LIBRAW_EXCEPTION_ALLOC;
+ }
else
throw LIBRAW_EXCEPTION_DECODE_RAW; // Only float deflated supported